import numpy as np
from armijo import armijo 
def gradient_descent(func, gfunc, x0, eps, k, maxk):
    g = gfunc(x0)
    d = -g
    if k >= maxk or np.linalg.norm(d) < eps:
        return x0, func(x0), k
    dk = armijo(x0,d,g,func=func,rho=0.5,sigma=0.4,m=0,maxm=20)
    return gradient_descent(func, gfunc, x0+dk, eps ,k+1, maxk)


import sys
sys.setrecursionlimit(100000000)


result = gradient_descent(func = lambda x:100*(x[1]-x[0])**2 + (1-x[0])**2,
                        gfunc = lambda x: np.array([-400*x[0]*(x[1]-x[0]**2)-2*(1-x[0]),200*(x[1]-x[0]**2)]),
                        x0=[0,0],eps=1e-5,k=0,maxk=5000)
print(result)
